<template>
    <van-pull-refresh v-model="isLoading" success-text="刷新成功" @refresh="OnRefresh">
        <van-list v-model:loading="loading" :offset="10" :finished="finished" finished-text="没有更多了" @load="OnLoad">
            <div>

            </div>
        </van-list>
    </van-pull-refresh>
    <Tabbar></Tabbar>
</template>

<script setup>
const { proxy } = getCurrentInstance()
const user = proxy.$user.value;
const activelist = ref([])

const page = ref(1);
const finished = ref(false)
const isLoading = ref(false);
const loading = ref(false);

// 下拉刷新
const OnRefresh = () => {
    isLoading.value = true;
    loading.value = true;
    finished.value = false;
    activelist.value = [];
    page.value = 1;

    setTimeout(OnLoad, 1500)
};


// 上拉加载
const OnLoad = async () => {
    if (isLoading.value === true) isLoading.value = false;
    const params = {
        page: page.value,
        id: user.id,
    }

    const res = await proxy.$http.post({
        url: '/active/getactivelist',// 接口地址
        params
    })

    loading.value = false;
    // finished.value = true;

    if (res.code === 1) {
        let count = res.data.count;
        activelist.value = activelist.value.concat(res.data.item);

        if (activelist.value.length >= count) {
            finished.value = true;
            return false;
        }

        page.value += 1;
    } else {
        finished.value = true;
        proxy.$fail(res.msg);
    }
}


</script>

<style></style>
